import { cpus } from 'node:os'
import path from 'node:path'

const PROJECT_DIR = path.resolve(import.meta.dirname, '..')
const SRC_DIR = path.join(PROJECT_DIR, 'src')
const DIST_DIR = path.join(PROJECT_DIR, 'dist')
const BUILD_DIR = path.join(PROJECT_DIR, 'build')
const VENDOR_DIR = path.join(BUILD_DIR, 'vendor')
const WASM_FILE = 'MediaInfoModule.wasm'

const TRACK_TYPES = ['General', 'Video', 'Audio', 'Text', 'Image', 'Menu', 'Other']

const WASM_INITIAL_MEMORY = 2 ** 25 // 32 MiB

// Global variable name for UMD build
const UMD_NAME = 'MediaInfo'

const LIBMEDIAINFO_VERSION = '25.07'
const LIBZEN_VERSION = '0.4.41'

const CXXFLAGS = '-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -fno-rtti -fno-exceptions'

// switch off features to save some bytes
const MediaInfoLib_CXXFLAGS = `-I ../../../Source -I ../../../../ZenLib/Source -s USE_ZLIB=1 \
  -DMEDIAINFO_ADVANCED_YES \
  -DMEDIAINFO_MINIMAL_YES \
  -DMEDIAINFO_EXPORT_YES \
  -DMEDIAINFO_SEEK_YES \
  -DMEDIAINFO_READER_NO \
  -DMEDIAINFO_REFERENCES_NO \
  -DMEDIAINFO_GRAPH_NO \
  -DMEDIAINFO_GRAPHVIZ_NO \
  -DMEDIAINFO_ARCHIVE_NO \
  -DMEDIAINFO_FIXITY_NO \
  -DMEDIAINFO_CSV_NO \
  -DMEDIAINFO_CUSTOM_NO \
  -DMEDIAINFO_EBUCORE_NO \
  -DMEDIAINFO_FIMS_NO \
  -DMEDIAINFO_MPEG7_NO \
  -DMEDIAINFO_PBCORE_NO \
  -DMEDIAINFO_REVTMD_NO \
  -DMEDIAINFO_NISO_NO \
  -DMEDIAINFO_MINIMIZESIZE \
  -DMEDIAINFO_TRACE_NO \
  -DMEDIAINFO_FILTER_NO \
  -DMEDIAINFO_DUPLICATE_NO \
  -DMEDIAINFO_MACROBLOCKS_NO \
  -DMEDIAINFO_NEXTPACKET_NO \
  -DMEDIAINFO_EVENTS_NO \
  -DMEDIAINFO_DEMUX_NO \
  -DMEDIAINFO_IBI_NO \
  -DMEDIAINFO_CONFORMANCE_YES \
  -DMEDIAINFO_DIRECTORY_NO \
  -DMEDIAINFO_LIBCURL_NO \
  -DMEDIAINFO_LIBMMS_NO \
  -DMEDIAINFO_READTHREAD_NO \
  -DMEDIAINFO_MD5_NO \
  -DMEDIAINFO_SHA1_NO \
  -DMEDIAINFO_SHA2_NO \
  -DMEDIAINFO_AES_NO \
  -DMEDIAINFO_JNI_NO \
  -DMEDIAINFO_TRACE_FFV1CONTENT_NO \
  -DMEDIAINFO_COMPRESS \
  -DMEDIAINFO_DECODE_NO \
  -DMEDIAINFO_IBIUSAGE_NO`

const CPU_CORES = cpus().length

export {
  BUILD_DIR,
  CPU_CORES,
  CXXFLAGS,
  DIST_DIR,
  LIBMEDIAINFO_VERSION,
  LIBZEN_VERSION,
  MediaInfoLib_CXXFLAGS,
  PROJECT_DIR,
  SRC_DIR,
  TRACK_TYPES,
  UMD_NAME,
  VENDOR_DIR,
  WASM_FILE,
  WASM_INITIAL_MEMORY,
}
